home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / program / 317 / asmsrc / gdb-symb.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-20  |  3.4 KB  |  132 lines

  1. /* gdb_symbols.c - */
  2.   
  3. /* Copyright (C) 1987 Free Software Foundation, Inc.
  4.  
  5. This file is part of Gas, the GNU Assembler.
  6.  
  7. The GNU assembler is distributed in the hope that it will be
  8. useful, but WITHOUT ANY WARRANTY.  No author or distributor
  9. accepts responsibility to anyone for the consequences of using it
  10. or for whether it serves any particular purpose or works at all,
  11. unless he says so in writing.  Refer to the GNU Assembler General
  12. Public License for full details.
  13.  
  14. Everyone is granted permission to copy, modify and redistribute
  15. the GNU Assembler, but only under the conditions described in the
  16. GNU Assembler General Public License.  A copy of this license is
  17. supposed to have been given to you along with the GNU Assembler
  18. so you can know your rights and responsibilities.  It should be
  19. in a file named COPYING.  Among other things, the copyright
  20. notice and this notice must be preserved on all copies.  */
  21.  
  22. /*
  23.  * During assembly, note requests to place symbol values in the GDB
  24.  * symbol file. When symbol values are known and the symbol file is
  25.  * in memory, place the symbol values in the memory image of the file.
  26.  *
  27.  * This has static data: it is not data_sharable.
  28.  *
  29.  * gdb_symbols_begin ()
  30.  *        Call once before using this package.
  31.  *
  32.  * gdb_symbols_fixup (symbolP, offset_in_file)
  33.  *        Remember to put the value of a symbol into the GDB file.
  34.  *
  35.  * gdb_symbols_emit  ()
  36.  *        Perform all the symbol fixups.
  37.  *
  38.  * uses:
  39.  *    xmalloc()
  40.  *    gdb_alter()
  41.  */
  42.  
  43. #include "as.h"
  44. #include "struc-symbol.h"
  45.  
  46. #define SYM_GROUP (100)        /* We allocate storage in lumps this big. */
  47.  
  48.  
  49. struct gdb_symbol        /* 1 fixup request. */
  50. {
  51.   symbolS *    gs_symbol;
  52.   long int    gs_offset;    /* Where in GDB symbol file. */
  53. };
  54. typedef struct gdb_symbol gdb_symbolS;
  55.  
  56. struct symbol_fixup_group
  57. {
  58.   struct symbol_fixup_group *    sfg_next;
  59.   gdb_symbolS            sfg_item [SYM_GROUP];
  60. };
  61. typedef struct symbol_fixup_group symbol_fixup_groupS;
  62.  
  63. static symbol_fixup_groupS *    root;
  64. static short int        used; /* # of last slot used. */
  65.                 /* Counts down from SYM_GROUP. */
  66.  
  67. static symbol_fixup_groupS *    /* Make storage for some more reminders. */
  68. new_sfg ()
  69. {
  70.   symbol_fixup_groupS *        newP;
  71.   char *            xmalloc();
  72.  
  73.   newP = (symbol_fixup_groupS *) xmalloc ((long)sizeof(symbol_fixup_groupS));
  74.   newP -> sfg_next = root;
  75.   used = SYM_GROUP;
  76.   root = newP;
  77.   return (newP);
  78. }
  79.  
  80.  
  81. void
  82. gdb_symbols_begin ()
  83. {
  84.   root = 0;
  85.   (void)new_sfg ();
  86. }
  87.  
  88.  
  89. void                /* Build a reminder to put a symbol value */
  90. gdb_symbols_fixup (sy, offset)    /* into the GDB symbol file. */
  91.      symbolS *    sy;        /* Which symbol. */
  92.      long int    offset;        /* Where in GDB symbol file. */
  93. {
  94.   register symbol_fixup_groupS *    p;
  95.   register gdb_symbolS *        q;
  96.       
  97.   p = root;
  98.   know( used >= 0 );
  99.   if ( used == 0)
  100.     {
  101.       p = new_sfg ();
  102.     }
  103.   q = p -> sfg_item + -- used;
  104.   q -> gs_symbol = sy;
  105.   q -> gs_offset = offset;
  106. }
  107.  
  108. void
  109. gdb_symbols_emit ()        /* Append GDB symbols to object file. */
  110. {
  111.   symbol_fixup_groupS *    sfgP;
  112.   void gdb_alter();
  113.   
  114.   for (sfgP = root;  sfgP;  sfgP = sfgP -> sfg_next)
  115.     {
  116.       register gdb_symbolS *    gsP;
  117.       register gdb_symbolS *    limit;
  118.  
  119.       limit = sfgP -> sfg_item +
  120.     (sfgP -> sfg_next ? 0 : used);
  121.       for (gsP = sfgP -> sfg_item + SYM_GROUP - 1;
  122.        gsP >= limit;
  123.        gsP --)
  124.     {
  125.       gdb_alter (gsP -> gs_offset,
  126.              (long int) gsP -> gs_symbol -> sy_value);
  127.     }
  128.     }
  129. }
  130.  
  131. /* end: gdb_symbols.c */
  132.